﻿using System.Collections.Generic;
using System.Globalization;
using Halk.Analyser;
using Halk.Model;

namespace Halk.Spider
{
    public class SpiderBase
    {
        protected int RepeatTimes { get; set; }

        protected Config.RuleEntity FirstRule;

        protected AnalyseArticlelist _firstAnalyseArticleList;

        protected AnalyseArticlelist FirstAnalyseArticleList
        {
            get { return _firstAnalyseArticleList ?? (_firstAnalyseArticleList = new AnalyseArticlelist()); }
        }

        protected AnalyseArticle _firstAnalyseArticle;

        protected AnalyseArticle FirstAnalyseArticle
        {
            get { return _firstAnalyseArticle ?? (_firstAnalyseArticle = new AnalyseArticle()); }
        }

        protected AnalyseBookReader _firstAnalyseBookReader;

        protected AnalyseBookReader FirstAnalyseBookReader
        {
            get { return _firstAnalyseBookReader ?? (_firstAnalyseBookReader = new AnalyseBookReader()); }
        }

        protected AnalyseChapter _firstAnalyseChapter;

        protected SpiderBase()
        {
            RepeatTimes = 0;
        }

        protected AnalyseChapter FirstAnalyseChapter
        {
            get { return _firstAnalyseChapter ?? (_firstAnalyseChapter = new AnalyseChapter()); }
        }

        protected void PrintNovel(string ruleFlag, ArticleInfo article)
        {
            Utils.LogManage.Instace().Info(true, ruleFlag);
            Utils.LogManage.Instace().Info(true, article.articleid.ToString(CultureInfo.InvariantCulture));
            Utils.LogManage.Instace().Info(true, article.articlename);
            Utils.LogManage.Instace().Info(true, article.author);
            Utils.LogManage.Instace().Info(true, article.sortid.ToString(CultureInfo.InvariantCulture));
            Utils.LogManage.Instace().Info(true, article.cover);
            Utils.LogManage.Instace().Info(true, article.contentslink);
            Utils.LogManage.Instace().Info(true, article.intro);
        }

        protected void PrintChapters(string ruleFlag, IEnumerable<ChapterInfo> chapters)
        {
            foreach (ChapterInfo chapterInfo in chapters)
            {
                string msg = string.Format("{0}>>{1} {2} {3} {4} {5}",
                                           ruleFlag,
                                           chapterInfo.articlename,
                                           chapterInfo.volumeid,
                                           chapterInfo.chapterid,
                                           chapterInfo.chapterorder,
                                           chapterInfo.chaptername);
                Utils.LogManage.Instace().Info(true, msg);
            }
        }
    }
}
